import { request } from '../../request/index.js'

// pages/group-order-detail/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isGet: true,
    orderId: '',
    orderInfo: {},
    orderAddress: {},
    fruitGoodsInfo: []
  },
  //确认是否订单已被取走
  async handleConfirm(e) {
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const { isGet, orderId } = options
    this.setData({
      isGet,
      orderId
    })
  },
  //获取订单详情信息
  async getOrderDetail(header) {
    const { orderId } = this.data
    const res = await request({ url: '/order/' + orderId, data: { orderId }, header })
    this.setData({
      orderInfo: res.data
    })
  },
  //获取商品详情
  async getOrderGoods(header) {
    const { orderId } = this.data
    const res = await request({ url: '/order/' + orderId + '/goods', data: { orderId }, header })
    this.setData({
      fruitGoodsInfo: res.data
    })
  },
  //获取订单地址信息
  async getOrderAddress(header) {
    const { orderId } = this.data
    const res = await request({ url: '/order/' + orderId + '/address', data: { orderId }, header })
    this.setData({
      orderAddress: res.data
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    const token = wx.getStorageSync("token");
    const header = { token }
    this.getOrderDetail(header)
    this.getOrderGoods(header)
    this.getOrderAddress(header)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})